package com.caishi.lkx.exam.service;

import com.caishi.lkx.exam.model.QuestionModel;
import com.caishi.lkx.exam.vo.QuestionStructureVo;
import com.caishi.lkx.exam.vo.QuestionVo;
import com.caishi.lkx.exam.vo.SpecialConditionVo;
import com.zzw.common.entity.BSService;
import com.zzw.common.exception.BizRuntimeException;
import com.caishi.lkx.exam.QuestionCollectionBlockItem;
import com.caishi.lkx.exam.dto.QuestionSimpleDto;
import com.caishi.lkx.exam.dto.QuestionSourceDto;
import com.caishi.lkx.exam.ienum.type.QuestionType;


import java.math.BigDecimal;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * @author by Jansia
 * @Date 2022/1/10 10:34
 * @Description
 */
public interface IQuestionService extends BSService<QuestionModel, String> {

    @Override
    @Deprecated
    default boolean insertBatch(List<QuestionModel> entityList, int batchSize) {
        throw new BizRuntimeException();
    }

    @Override
    @Deprecated
    default boolean insertBatch(List<QuestionModel> entityList) {
        throw new BizRuntimeException();
    }

    boolean insertBatch(List<QuestionModel> entityList, String examId);

    QuestionModel insert(QuestionModel entity, String examId);

    /**
     * 计算试题质量
     *
     * @param questionModel
     * @return
     */
    BigDecimal additionQualityLevel(QuestionModel questionModel);


    /**
     * 获取试题详情 包括复合体的子题 包含答案
     *
     * @param resourceId
     * @return
     */
    QuestionModel getQuestionById(String resourceId);

    /**
     * 获取复合题的子题
     *
     * @param id 复合题id
     * @return
     */
    List<QuestionModel> getCombineList(String id);

    /**
     * 修改试题的隐藏状态
     *
     * @param ids
     * @param isHide 是否隐藏
     * @return
     */
    Boolean isHideQuestion(List<String> ids, Boolean isHide);

    /**
     * 获取试题基本信息 包含答案
     *
     * @param qid
     * @return
     */
    QuestionSimpleDto questionSimpleData(String qid);

    /**
     * 客户端获取试题基本信息
     *
     * @param id
     * @return
     */
    QuestionVo clientGetQuestionById(String id);

    /**
     * 向客户端查询试题集合
     * 包含答案
     *
     * @param ids
     * @return
     */
    List<QuestionVo> clientQuestionCollection(List<String> ids, String industryId, String examId, Long categoryId);

    List<QuestionVo> clientQuestionCollection(List<String> ids, String industryId, String examId, Long categoryId, boolean type);


    /**
     * 向客户端查询试题集合
     * 只包含题型结构
     *
     * @param ids
     * @return
     */
    List<QuestionStructureVo> questionCollectionStructure(List<String> ids, String industryId, String examId, Long categoryId);

    /**
     * 获取试题的答案 仅包含答案
     *
     * @param id
     * @return
     */
    QuestionModel answerModel(String id);

    /**
     * 试题答案解密
     *
     * @param base64
     * @param userId
     * @param collectId
     * @return
     */
    Object answerDecrypt(String base64, String userId, String collectId);

    /**
     * 试题答案加密
     *
     * @param answer
     * @param userId
     * @param collectId
     * @return
     */
    String answerEncrypt(Object answer, String userId, String collectId);

    /**
     * 获取题型名称
     * * @param typeId
     *
     * @param questionType
     * @return
     */
    String questionTypeName(String typeId, QuestionType questionType);


    /**
     * 根据试题数随机生成集合
     *
     * @param categoryId
     * @param types        选择的题型
     * @param count        随机生成数量
     * @param inIds        包含的试题id
     * @param descCall     试题集合描述生成
     * @param allScoreCall 试题总分回调
     * @return
     */
    List<QuestionCollectionBlockItem> generateQuestionBlock(Long categoryId, List<SpecialConditionVo.TY> types, Integer count, List<String> inIds,
                                                            Function<QuestionCollectionBlockItem, String> descCall, Consumer<BigDecimal> allScoreCall);

    /**
     * 试题属于那份 试卷和章节
     *
     * @param cid        科目
     * @param questionId 试题
     * @return
     */
    QuestionSourceDto questionSource(String questionId);

    /**
     * 根据科目id获取散题
     *
     * @param categoryId
     * @return
     */
    List<String> getScatteredQuestion(Long categoryId, Boolean isUse);

}
